package org.lex.swing.util;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import org.lex.swing.Swings;
import org.lex.swing.widgets.MazePane;


/*
 * һ��Leading��ť��n��Trailing��ť
 *
 */
public class L1TnButtons extends JPanel {
	private static final Border trailingPaneBorder = new EmptyBorder(0, 0, 0, 0);
	private static final Border thisBorder = new EmptyBorder(11, 12, 11, 0);
	private final JButton leadingButton;
	private final Buttons trailingPane;

	public static void main(String[] args) {
		Swings.show(new CenterSouthPane(new MazePane(), create("Default", "OK", "Close")), false);
	}

	public static L1TnButtons create(String leading, String... trailings) {
		return new L1TnButtons(new JButton(leading), Buttons.createButtons(trailings));
	}

	public static <T extends Action> L1TnButtons create(T leading, T... trailings) {
		return new L1TnButtons(new JButton(leading), Buttons.createButtons(trailings));
	}

	public L1TnButtons(JButton leading, JButton... trailings) {
		super();
		this.leadingButton = leading;
		this.trailingPane = Buttons.trailing(trailings);
		this.trailingPane.setBorder(trailingPaneBorder);
		this.setBorder(thisBorder);
		initialize();
	}

	public JButton getLeadingButton() {
		return leadingButton;
	}

	public JButton getTrailingButton(int index) {
		return this.trailingPane.getButton(index);
	}

	private Buttons getTrailingPane() {
		return trailingPane;
	}

	private void initialize() {
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.anchor = GridBagConstraints.LINE_START;
		gridBagConstraints.insets = new Insets(0, 0, 0, 11);
		gridBagConstraints.gridy = 0;
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
		gridBagConstraints3.gridx = 1;
		gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints3.weightx = 10.0;
		gridBagConstraints3.anchor = GridBagConstraints.LINE_END;
		gridBagConstraints3.gridy = 0;
		this.setLayout(new GridBagLayout());
		this.add(getLeadingButton(), gridBagConstraints);
		this.add(getTrailingPane(), gridBagConstraints3);
	}
}
